package com.zzptc.syl.viewpager;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class OneFragment extends Fragment {

    //建立集合
    private List<Entry> data = new ArrayList<>();
    private List<Entry> data2 = new ArrayList<>();

    public static OneFragment newInstance() {
        OneFragment fragment = new OneFragment();
        Bundle args = new Bundle();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        //绑定视图
        View inflate =inflater.inflate(R.layout.fragment_one, container, false);
        //实例化折线控件
        LineChart lineChart = (LineChart)inflate.findViewById(R.id.line_chart);
        //给折现中添加数据
        data.add(new Entry(0,3));
        data.add(new Entry(5,7));
        data.add(new Entry(6,9));
        //双折线
        data2.add(new Entry(2,5));
        data2.add(new Entry(3,7));
        data2.add(new Entry(5,9));
        //设置折线的数据+图例
        LineDataSet yeye = new LineDataSet(data, "耶耶");
        LineDataSet wawa = new LineDataSet(data2, "哇哇");
        //建立一个数组
        LineData lineData = new LineData();
        //将数组添加至条形图中
        lineData.addDataSet(wawa);
        lineData.addDataSet(yeye);
        //将数据设置在折线图中
        lineChart.setData(lineData);
        //返回视图
        return inflate;
    }
}